package AsLayers.Format
{
	import AsLayers.Geometry.IGeometry;
	import AsLayers.Geometry.Point;
	
	public class WKT implements IFormat
	{
		
	    private var regExes= {
            'typeStr': /^\s*(\w+)\s*\(\s*(.*)\s*\)\s*$/,
            'spaces': /\s+/,
            'parenComma': /\)\s*,\s*\(/,
            'doubleParenComma': /\)\s*\)\s*,\s*\(\s*\(/,  
            'trimParens': /^\s*\(?(.*?)\)?\s*$/
        }
        private var parse={
        	'point':function(str:String):Point{
                var coords =str.split(this.regExes.spaces);
                return new Point(coords[0], coords[1]);
        	 }
        }
		public function WKT()
		{
	      
		}

		public function read(data:String)
		{
            var features, type:String, str:String;
            var matches = this.regExes.typeStr.exec(data);
            if(matches) {
               type = matches[1].toLowerCase();
               str = matches[2];
               if(this.parse[type]) {
                  features = this.parse[type](str);
                }
            } 
            
            return features;
		}
		
		public function write(object:IGeometry)
		{

		}
		
	}
}